package org.ahuanlien.crm.web.controller;


import org.ahuanlien.crm.domain.Salary;
import org.ahuanlien.crm.query.StaffManagementQueryObject;
import org.ahuanlien.crm.service.IEmployeeService;
import org.ahuanlien.crm.service.ISalaryService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("salary")
public class SalaryController {

	@Autowired
	private ISalaryService salaryService;

	//打开页面和数据获取分开
	@RequestMapping("view")
	public String view() {
		return "salary/view";
	}

	@RequestMapping("query")
	@ResponseBody
	public PageResult query(StaffManagementQueryObject qo) {
		PageResult result = salaryService.query(qo);
		return result;
	}



	@RequestMapping("saveOrUpdate")
	@ResponseBody
	public JSONResult saveOrUpdate(Salary salary) {
		try {
			salaryService.saveOrUpdate(salary);
		} catch (Exception e) {
			e.printStackTrace();
			return JSONResult.mark("操作失败");
		}
		return JSONResult.success("操作成功");
	}

	@RequestMapping("selectAll")
	@ResponseBody
	public List<Salary> selectAll(){
		return salaryService.selectAll();
	}

	@RequestMapping("selectByPrimaryKey")
	@ResponseBody
	public Salary selectByPrimaryKey(Long id){
		return salaryService.selectByPrimaryKey(id);
	}
}
